package com.linjm.util;
import org.apache.xerces.impl.xpath.regex.REUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;

//RedisConfig负责在spring容器启动时自动注入
@Configuration
public class RedisConfig {
    //读取配置文件中的redis的ip地址,如果未在配置文件中读取都host，则默认值为disable
    @Value("${spring.redis.host:disabled}")
    private String host;

    @Value("${spring.redis.port:0}")
    private int port;

    @Value("${spring.redis.database:0}")
    private int database;

    // 将获取的数据传入到initJedisPool方法中
    @Bean
    public RedisUtil getRedisUtil(){
        if (host.equals("disabled")){
            return null;
        }
        RedisUtil redisUtil = new RedisUtil();
        // 调用initJedisPool方法将值传入
        redisUtil.initJedisPool(host,port,database);
        return redisUtil;
    }

}
